import { del, get, post, put } from '@/common/js/httpHelper'
import * as url from '@/common/js/interfaces'

const getFunctionListAuth = async (functionId) => {
  const result = await get(url.findFunctionListAuth, {functionId: functionId})
  return result.data
}

const getFunctionListWithPageParams = async (pageParams) => {
  const result = await post(url.findFunctionListWithPageParams, pageParams)
  return result.data
}

const addFunction = async (newFunction) => {
  const result = await post(url.functionList, newFunction)
  return result.data
}

const updateFunction = async (func) => {
  const result = await put(url.functionList + '/' + func.id, func)
  return result.data
}

const deleteFunctionById = async (functionId) => {
  const result = await del(url.functionList + '/' + functionId)
  return result.data
}

const addFunctionAuth = async (newFunctionAuth) => {
  const result = await post(url.functionAuth + '/add', newFunctionAuth)
  return result.data
}

const deleteFunctionAuth = async (functionAuthId) => {
  const result = await del(url.functionAuth + '/' + functionAuthId)
  return result.data
}

export default {
  getFunctionListAuth: getFunctionListAuth,
  getFunctionListWithPageParams: getFunctionListWithPageParams,
  addFunction: addFunction,
  updateFunction: updateFunction,
  deleteFunctionById: deleteFunctionById,
  addFunctionAuth: addFunctionAuth,
  deleteFunctionAuth: deleteFunctionAuth
}
